home *** CD-ROM | disk | FTP | other *** search
- E! for Windows - Technical Note #008
- *********************************************
- Using the EW API from an external application
- *********************************************
-
- The EW API has been primarily designed to be used from an extension DLL
- loaded from EW itself.
-
- However there's room for another kind of use. An external Windows program
- can interact with EW using the EW API. For example, we could (we certainly
- will) write a generic DDE Server programm accepting DDE messages and passing
- them to the EW API to communicate with EW itself.
-
- If you decide to write such a program, you must be cautious and there's a
- few things you should be aware of.
-
- When triggering certain functions, the EW API sends messages to the current
- Editor via the current Edit Window. The current Edit Window handle is
- continuously updated by EW and passed to the API DLL. This handle is stored
- in EWAPI.DLL's own data segment. When an Edit Window loses the focus, the
- handle is temporarily reset to 0 until another Edit Window gets the focus
- again. Meanwhile, there's no way to trigger an Edit Window related function
- because the call will be sent to the nowhere land. After all, an editing
- function has to apply to a given text. Please see below for a list a API
- functions that can be called at any time.
-
- Your application can check whether an Edit Window has the focus by calling
- EWGetCurrentEditor or EWGetWindowHandle. Both functions return 0 if no Edit
- Window has the focus.
-
- Since they can only be triggered when an Editor is active, this problem
- doesn't exist with Extension DLLs (except for hooks installed for certain
- events).
-
- Another choice would have been to call the API editing functions for a given
- Editor explicitly. This would have made writing Extension DLLs a little bit
- more difficult because of the programming overhead needed to keep track of
- the currently valid Editors (maintaining a list of Editors and Edit Windows,
- setting up a notification hook to update the lists, etc...). Since using the
- EW API from an external application will not happen very often we have
- decided to make writing extension DLLs easier.
-
- There are two methods for solving this problem.
-
- Method #1
- *********
-
- Before triggering one of the Edit Window related functions, your application
- must first set the focus to one of the Edit Window. You can keep track of
- the different Editors and Edit Windows by using the enumeration functions
- provided by the API. Once the focus has been set to an Edit Window, your
- application can call any API function safely while remaining in the
- background. Of course, once your application's current message has been
- processed, EW will immediately gain the input focus.
-
- A good way to always know which Editor or Edit Window was the last one that
- had the focus is to install a notification hook (please see documentation)
- with the EWNotify_ActWinChanged event code. Such a hook can easily keep track
- of the currently active Edit Window.
-
- Method #2
- *********
-
- Before triggering an Edit Window related function, you can explicity set the
- current Editor and the Edit Window handle by using 2 undocumented functions
- that are normally used only by EW (both functions remain officially
- "undocumented" but have been added to EWAPIIMP.PAS and EWAPI.H):
-
- **************************************************************************
- procedure EWSetEditorId(EditorId : longint);
- void FAR PASCAL EWSetEditor(long EditorId);
-
- This function forces the current EditorId without giving it the focus.
- EditorId must be a valid Editor ID that you have retrieved earlier in your
- program by using the relevant API functions (EWEnumEditors or
- EWGetCurrentEditor).
-
-
- **************************************************************************
- procedure EWSetWindowHandle(H : HWnd);
- void FAR PASCAL EWSetWindowHandle(unsigned int H);
-
- This function forces the handle of the current Edit Window without giving it
- the focus. H must be a valid Edit Window handle that you have retrieved
- earlier in your program by using the EWGetWindowHandle or EnumClones
- functions. Any call to an Edit Window related function will be forwarded to
- that window.
-
-
-
- If you use these functions, please make sure that you keep both values in
- synch, that is, any window handle passed to EWSetWindowHandle must
- correspond to an Edit Window that belongs to the Editor which ID has been
- passed to EWSetEditorId. You can change the current Edit Window handle
- without changing the current Editor if the latter has clone windows but you
- can't change the current Editor Id whithout changing the Edit Window handle.
-
- Any call to EWSetCurrentEditor will reset these values. Giving manually the
- focus to any Edit Window will also update these values (EW will call both
- functions).
-
- This method is more elegant than the previous one but you should be very
- cautious when using it. Also, you should be aware that some functions may
- result in giving the focus to the target Edit Window (for example, when
- triggering functions that open a dialog box).
-
-
- Here is a list of EW API functions that are not related to an Edit Window.
- You can call them whenever you want, even if no Edit Window currently has
- the focus:
-
-
- EWEnumEditors EWEnumClones EWSetHook
- EWRemoveHook EWEditFile EWSetCurrentEditor
- EWGetCurrentEditor EWFindRegular EWAddMenuEntry
- EWRemoveMenuEntry EWCallUserExt EWGetGlobalFlag
- EWSetGlobalFlag EWGetLocalFlag EWSetLocalFlag
- EWGetSearchFlag EWSetSearchFlag EWSetFindPattern
- EWGetVersion EWGetInstance EWSaveAll
-
-
-
- EWGetCurrentEditor will return 0 if no Edit Windows has the focus unless you
- have forced the current Editor Id using EWSetEditorId.
-
- If you call EWCallUserExt, be sure that the called Extension DLL will not in
- turn trigger calls to Edit Window related functions while no Edit Window has
- the focus. This will do no harm but you will not get the expected result.
-
- If you have any problem using the EW API, please let us know. We'll be
- pleased to help you and to add your suggestions to our todo list.
-
- Patrick Philippot
- 07/02/93
-